// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 * Creator: yanking
 * Create time: 2022-02-21 13:53
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.leetCode.singleNumber;

import java.util.HashMap;

public class singleNumber_ {
    // 寻找给定数组中只出现一次的数字
    public int singleNumber(int[] nums) {
        HashMap<Integer, Integer> countNum = new HashMap<>();
        int res = 0;
        for (int num : nums) {
            Integer times = countNum.getOrDefault(num, 0);
            countNum.put(num, ++times);
        }
        for (Integer num : countNum.keySet()) {
            if (countNum.get(num) == 1) {
                res = num;
                break;
            }
        }
        return res;
    }

}
